

#import "PUNoTitleTipView.h"
@interface PUNoTitleTipView()
@property(nonatomic,retain)UIView *nohahaAlphaView;
@property(nonatomic,retain)NSString *content;
@property(nonatomic,retain)NSString *confirmStr;
@property(nonatomic,retain)NSString *cancelStr;
@property(nonatomic)int buttonCount;
@end
@implementation PUNoTitleTipView

-(instancetype)initCPTipViewWithContent:(NSString *)content confirmStr:(NSString *)confirmStr cancelStr:(NSString *)cancelStr buttonCount:(int)buttonCount
{
    self = [super init];
    if (self) {
   
        self.frame = [UIScreen mainScreen].bounds;
//        self.backgroundColor = [UIColor blackColor];
//        self.alpha = 0.3;
        [[UIApplication sharedApplication].delegate.window addSubview:self];
        self.content=content;
        self.confirmStr=confirmStr;
        self.cancelStr=cancelStr;
        self.buttonCount=buttonCount;
        [self _initViews];
    }
    return self;
}

-(void)_initViews{
    
    self.nohahaAlphaView = [[UIView alloc]init];
    self.nohahaAlphaView.frame =self.bounds;
    self.nohahaAlphaView.alpha = 0.3;
    self.nohahaAlphaView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    [self addSubview:self.nohahaAlphaView];
    
   
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor=[UIColor whiteColor];
    bgView.center = self.center;
    bgView.bounds = CGRectMake(0, 0, self.frame.size.width*0.786, self.frame.size.width*0.786*0.464);
    bgView.layer.masksToBounds = YES;
    bgView.layer.cornerRadius = self.frame.size.width*0.786*0.067;
    [self addSubview:bgView];
    
    
//    UIImageView *bgImage=[[UIImageView alloc]init];
//    bgImage.frame=bgView.bounds;
//    bgImage.image=[UIImage imageNamed:@"bgViewXiao"];
//    [bgView addSubview:bgImage];
    

    
    UILabel *label2 = [[UILabel alloc] init];
    label2.frame = CGRectMake(0,bgView.frame.size.height*0.145,bgView.frame.size.width,bgView.frame.size.height*0.182);
//    label.backgroundColor=[UIColor blueColor];
    label2.textAlignment=NSTextAlignmentCenter;
    label2.text=self.content;
    label2.font=[UIFont systemFontOfSize:17];
    label2.textColor = [UIColor colorWithHex:0x000000];
    label2.numberOfLines=0;
    [bgView addSubview:label2];

    
    if (self.buttonCount==2) {
        //左边按钮
        UIButton *updateButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [updateButton setBackgroundColor:[UIColor whiteColor]];
        updateButton.frame = CGRectMake(bgView.frame.size.width*0.068, bgView.frame.size.height*0.474, bgView.frame.size.width*0.413, bgView.frame.size.width*0.413*0.426);
        updateButton.clipsToBounds = YES;
        updateButton.layer.cornerRadius =updateButton.frame.size.height/2;
        [updateButton addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [updateButton setTitle:self.cancelStr forState:UIControlStateNormal];
         updateButton.titleLabel.font = [UIFont systemFontOfSize: 18.0];
        [updateButton setTitleColor:[UIColor colorWithHex:0xFF729A] forState:UIControlStateNormal];
        updateButton.tag=1000;
        [bgView addSubview:updateButton];
        updateButton.layer.borderColor = [UIColor colorWithHex:0xFF729A].CGColor;
        updateButton.layer.borderWidth = 1.0;
        //右边按钮
        UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [rechargeBtn setBackgroundColor:[UIColor colorWithHex:0xFF729A]];
        rechargeBtn.frame = CGRectMake(bgView.frame.size.width*0.515,  bgView.frame.size.height*0.474,bgView.frame.size.width*0.413, bgView.frame.size.width*0.413*0.426);
        rechargeBtn.clipsToBounds = YES;
        rechargeBtn.layer.cornerRadius =rechargeBtn.frame.size.height/2;
        [rechargeBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [rechargeBtn setTitle:self.confirmStr forState:UIControlStateNormal];
         rechargeBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
        [rechargeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        rechargeBtn.tag=1001;
        [bgView addSubview:rechargeBtn];
    }else{
        //一个按钮
        UIButton *updateButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [updateButton setBackgroundColor:[UIColor colorWithHex:0xFF729A]];
        updateButton.frame = CGRectMake(bgView.frame.size.width*0.149, bgView.frame.size.height*0.474, bgView.frame.size.width*0.701, bgView.frame.size.width*0.701*0.212);
        updateButton.clipsToBounds = YES;
        updateButton.layer.cornerRadius =updateButton.frame.size.height/2;
    //    updateButton.layer.borderWidth = 1.0f;
    //    updateButton.layer.borderColor = [[UIColor colorWithHex:0xBCBCBC] CGColor];
        [updateButton addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [updateButton setTitle:self.confirmStr forState:UIControlStateNormal];
         updateButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
        [updateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        updateButton.tag=1001;
        [bgView addSubview:updateButton];
    }
    
}

-(void)btnClicked:(UIButton*)button{
    [self disMiss];
    //前往查看
    int index=0;
    //继续存证
    if (button.tag==1001) {
        index=1;
    }
    
    if ([self.delegate respondsToSelector:@selector(CPNoTitleTipViewbtnClickedIndex:)]) {
        [self.delegate CPNoTitleTipViewbtnClickedIndex:index];
    }
}
-(void)show
{
    CGRect frame = self.frame;
    frame.origin.y = 0;
    [UIView animateWithDuration:0.4 animations:^{
        self.frame = frame;
    }];
}
-(void)disMiss{

    [UIView animateWithDuration:0.05 animations:^{
        self.backgroundColor = [UIColor clearColor];
        self.alpha = 0;
        
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
